function [theta,distance] = NXTScan(varargin)
offset = 6;
reductionRatio = 2;
OpenUltrasonic(SENSOR_1);
mBL = NXTMotor('B', 'Power', -20, 'TachoLimit',80);
mBR = NXTMotor('B', 'Power', 50, 'TachoLimit',40);
mBR.SendToNXT();
Z = mBL.ReadFromNXT.TachoCount;
Z2 = 100;
i = 1;
mBR.SendToNXT();
mBR.WaitFor();
mBL.SendToNXT();
while (((Z == 0) | (Z2 == 0)) | (Z ~= Z2))
    theta(i) = mBL.ReadFromNXT.TachoCount;
    distance(i) = GetUltrasonic(SENSOR_1) + offset;
    Z2 = Z;
    Z = mBL.ReadFromNXT.TachoCount;
    i = i+1;
end
mBL.WaitFor();
theta = theta+40;
theta = theta*2*pi/360;
points = [sin(theta).*distance;cos(theta).*distance];
%plot(points(1,:),points(2,:),'rx')
mBR.SendToNXT();
mBR.WaitFor();
theta = theta(1:reductionRatio:end);
theta = -theta;
distance = distance(1:reductionRatio:end);